﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AutoLoL.Entities;
using AutoLoL.Logic;
using System.ComponentModel;
using AutoLoL.Logic.Factories;

namespace AutoLoL.Controls
{
    /// <summary>
    /// Interaction logic for MasteryEditorControl.xaml
    /// </summary>
    public partial class MasteryEditorControl : UserControl
    {
        public static DependencyProperty ViewModelProperty = DependencyProperty.Register("ViewModel", typeof(MasteryEditorViewModel), typeof(MasteryEditorControl));

        public MasteryEditorViewModel ViewModel
        {
            get { return (MasteryEditorViewModel)GetValue(ViewModelProperty); }
            set
            {
                SetValue(ViewModelProperty, value);
            }
        }

        public MasteryBuild MasteryBuild { get { return ViewModel.MasteryBuild; } }

        public MasteryEditorControl(MasteryBuild masteryBuild)
        {
            InitializeComponent();
            ViewModel = new MasteryEditorViewModel(masteryBuild);
            this.DataContext = ViewModel;
        }
    }

    public class MasteryEditorViewModel : DependencyObject
    {
        public MasteryBuild MasteryBuild { get; private set; }

        public ObservableCollection<MasteryTreeControl> MasteryTreeControls { get; private set; }

        public MasteryEditorViewModel(MasteryBuild masteryBuild)
        {
            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                this.MasteryBuild = masteryBuild;
                this.MasteryTreeControls = new ObservableCollection<MasteryTreeControl>();

                foreach (MasteryTree masteryTree in MasteryBuild.MasteryTrees)
                {
                    MasteryTreeControl masteryTreeControl = new MasteryTreeControl(masteryTree);
                    this.MasteryTreeControls.Add(masteryTreeControl);
                }
            }
        }
    }
}
